package cn.jinhe.doc.view.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import cn.jinhe.doc.base.BaseAction;
import cn.jinhe.doc.domain.Material;
import cn.jinhe.doc.domain.MaterialConsume;
import cn.jinhe.doc.domain.ServiceTopic;
import cn.jinhe.doc.util.QueryHelper;

@Controller
@Scope("prototype")
public class MaterialConsumeAction extends BaseAction<MaterialConsume>{

	private Long serviceTopicId;
	
	private Long materialId;
	
	private Long num;
	
	private String serachCondition;
	
	public String delete() throws Exception {
		materialConsumeService.delete(model.getId());
		return "toServiceTopicShow";	

	}

	public String addUI() throws Exception{
		new QueryHelper(Material.class, "m").preparePageBean(materialService, pageNum, pageSize);
		
		ServiceTopic  serviceTopic = serviceTopicService.getById(serviceTopicId);
		ActionContext.getContext().put("serviceTopic", serviceTopic);
		return "addUI";
		
	}
	public String add() throws Exception{
		
		// 封装
		// >> 表单字段，已经封装了title, content
		// model.setTitle(title);
		// model.setContent(content);
//		model.setTopic(topicService.getById(topicId));		
		model.setMaterial(materialService.getById(materialId));
		model.setServiceTopic(serviceTopicService.getById(serviceTopicId));
		model.setNum(model.getNum());
//		model.setMaterial(materialService.getById(materialId));
		materialConsumeService.save(model);
		return "toServiceTopicShow";	
	}
	public String editUI() throws Exception{
		MaterialConsume materialConsume=materialConsumeService.getById(model.getId());
		ActionContext.getContext().getValueStack().push(materialConsume);
		
		
		return "saveUI";
	}
	public String edit() throws Exception {
		//1,从数据库中取出原对象
		MaterialConsume materialConsume=materialConsumeService.getById(model.getId());		
		//2，设置要修改的属性
		materialConsume.setNum(model.getNum());
		materialConsumeService.update(materialConsume);
		
		return "toServiceTopicShow";
	}
	public String getSerachCondition() {
		return serachCondition;
	}
	public void setSerachCondition(String serachCondition) {
		this.serachCondition = serachCondition;
	}
	public Long getMaterialId() {
		return materialId;
	}

	public void setMaterialId(Long materialId) {
		this.materialId = materialId;
	}

	public Long getServiceTopicId() {
		return serviceTopicId;
	}

	public void setServiceTopicId(Long serviceTopicId) {
		this.serviceTopicId = serviceTopicId;
	}
	public Long getNum() {
		return num;
	}
	public void setNum(Long num) {
		this.num = num;
	}


}
